import { createRouter, createWebHistory } from 'vue-router'
// import store from '../store/index'
import { setTitle } from '../utils/index'
import Home from '../views/Home.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = createRouter({
  history: createWebHistory(),
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
  routes
})

router.beforeEach((to, from, next) => {
  setTitle(to.meta.title)
  // if (to.path == '/index' || to.path == '*') {
    next()
  // } else {
  //   if (store.state.token) {
  //     next()
  //   } else {
  //     store.commit('signOut')
  //     next({ path: '/index' })
  //   }
  // }
})

export default router
